package com.boful.test;

import java.io.FileInputStream;

public class TxtJude {
	private static void judgeTextCode(String strFilePath) {
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(strFilePath);
			int a = fis.read();
			int b = fis.read();
			if (a == 0xFF && b == 0xFE) {
				System.out.println("----------Unicode------");
			} else if (a == 0xFE && b == 0xFF) {
				System.out.println("----------UTF-16BE------");
			} else if (a == 0xEF && b == 0xBB) {
				System.out.println("----------UTF-8------");
			} else {
				System.out.println("----------GBK------");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (fis != null) {
					fis.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	
	public static void main(String[] args) {
		judgeTextCode("/home/ligson/test/doc/my.txt");
		judgeTextCode("/home/ligson/模块.txt");
	}
}
